﻿using innovations.ml.data;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using innovations.util.exts.mathdotnet;

namespace innovations.ml.test
{
    internal class Helpers
    {
        internal static DataManager LoadFile(string file)
        {
            CSVLoader csv1_1 = new CSVLoader(file);
            return csv1_1.Load();
        }

        /// <summary>
        /// Maps the two input features to quadratic features used in the regularization exercise.
        /// </summary>
        /// <param name="x1">First feature to regularize</param>
        /// <param name="x2">Second feature to regularize</param>
        /// <returns>Returns a new feature array with more features, comprising of X1, X2, X1.^2, X2.^2, X1*X2, X1*X2.^2, etc..</returns>
        internal static Matrix<double> MapFeatures(Vector<double> x1, Vector<double> x2)
        {
            int degree = 6;
            Matrix<double> m = new DenseMatrix(x1.Count, 1, 1.0);
            for (int i = 1; i <= degree; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    Vector<double> v = x1.PointwisePow(i - j).PointwiseMultiply(x2.PointwisePow(j));
                    m = m.InsertColumn(m.ColumnCount, v);
                }
            }
            return m;
        }

    }
}
